<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

if (!function_exists('calculateDays')) {

    function calculateDays($datefrom, $dateto, $convert_to_time = FALSE) {
        if ($convert_to_time == TRUE) {
            $days = ceil((strtotime($dateto) - strtotime($datefrom)) / 86400); // 60 * 60 * 24 = day
        } else {
            $days = ceil(($dateto - $datefrom) / 86400); // 60 * 60 * 24 = day
        }
        return $days;
    }

}

if (!function_exists('calculateAge')) {

    function calculateAge($timestamp = 0, $now = 0) {
        # default to current time when $now not given
        if ($now == 0)
            $now = time();

        # calculate differences between timestamp and current Y/m/d
        $yearDiff = date("Y", $now) - date("Y", $timestamp);
        $monthDiff = date("m", $now) - date("m", $timestamp);
        $dayDiff = date("d", $now) - date("d", $timestamp);

        # check if we already had our birthday
        if ($monthDiff < 0)
            $yearDiff--;
        elseif (($monthDiff == 0) && ($dayDiff < 0))
            $yearDiff--;

        # set the result: age in years
        $result = intval($yearDiff);

        # deliver the result
        return $result;
    }

}

if (!function_exists('prepareEncreseSearchDate')) {

    function prepareEncreseSearchDate($date, $i) {
        // prepare date for search
        // increase date for $i nr of days
        $day = date('d.m', $date) . '.1970';
        $day = strtotime($day);
        $day = strtotime('+' . $i . ' day', $day);

        return $day;
    }

}
?>